package io.gitee.twoke.generator.engine.impl.db;

import io.gitee.twoke.generator.engine.impl.persistence.entity.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Maintains a list of all the entities in order of dependency.
 */
public class EntityDependencyOrder {
	
	public static List<Class<? extends Entity>> DELETE_ORDER = new ArrayList<Class<? extends Entity>>();
	public static List<Class<? extends Entity>> INSERT_ORDER = new ArrayList<Class<? extends Entity>>();
	
	static {
		/*
		 * In the comments below:
		 * 
		 * 'FK to X' : X should be BELOW the entity
		 * 
		 * 'FK from X': X should be ABOVE the entity
		 * 
		 */
		DELETE_ORDER.add(PropertyEntityImpl.class);
		DELETE_ORDER.add(TemplateEntityImpl.class);
		DELETE_ORDER.add(TemplateFileEntityImpl.class);
		DELETE_ORDER.add(DataTableEntity.class);
		DELETE_ORDER.add(DataTableColumnEntity.class);

		INSERT_ORDER = new ArrayList<Class<? extends Entity>>(DELETE_ORDER);
		Collections.reverse(INSERT_ORDER);
	}

}